package net.ncraft.mc.ezframework.core.gui.einventory;

import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;

public class InvElementGroup {
    @Getter
    @Setter
    private EInventory inventory;
    @Getter
    private final List<InvElement> elements = new ArrayList<>();
    @Getter
    @Setter
    private InvElement nextPageElement;
    @Getter
    @Setter
    private InvElement previousPageElement;

    public InvElementGroup(EInventory inventory) {
        this(inventory, new InvElement[0]);
    }

    public InvElementGroup(EInventory inv, InvElement... elements) {
        this.inventory = inv;
        addElements(elements);
        nextPageElement = new InvElement(inventory.getSize() - 2, new ItemStack(Material.PAPER, 1));
        previousPageElement = new InvElement(inventory.getSize() - 3, new ItemStack(Material.PAPER, 1));
        nextPageElement.setEleType(InvElementType.FIXED);
        previousPageElement.setEleType(InvElementType.FIXED);
        nextPageElement.setDisplayName("Next Page");
        previousPageElement.setDisplayName("Previous Page");

        nextPageElement.setOnClick((i, p) -> {
            i.nextPage();
            i.updateTitle(i.getTitle() + " - Page " +i.getNowPage());
        });

        previousPageElement.setOnClick((i, p) -> {
            i.previousPage();
            i.updateTitle(i.getTitle() + " - Page " +i.getNowPage());
        });

        addElement(nextPageElement);
        addElement(previousPageElement);
    }

    public void addElement(InvElement element) {
        elements.add(element);
    }

    public void addElements(InvElement... elements) {
        for (InvElement element : elements) {
            addElement(element);
        }
    }


}
